const express = require('express');
const router = express.Router();
const upload = require('../middleware/upload');

// 上传图片
router.post('/image', upload.single('image'), (req, res) => {
  try {
    if (!req.file) {
      return res.status(400).json({
        success: false,
        error: '请选择要上传的图片',
        code: 400
      });
    }

    res.json({
      success: true,
      data: {
        url: `/uploads/${req.file.filename}`,
        original_name: req.file.originalname,
        file_size: req.file.size,
        file_type: req.file.mimetype
      },
      message: '上传成功'
    });
  } catch (error) {
    res.status(500).json({
      success: false,
      error: error.message,
      code: 500
    });
  }
});

module.exports = router; 